import {
  Entity,
  Column,
  PrimaryGeneratedColumn,
  CreateDateColumn,
  UpdateDateColumn,
  ManyToOne,
  JoinColumn,
} from 'typeorm';
import { User } from '../user/user.entity';

export enum NotificationType {
  BOOK_BORROWED = 'book_borrowed', // 图书被借阅
  BOOK_RETURNED = 'book_returned', // 图书被归还
  BOOK_COMMENTED = 'book_commented', // 图书被评论
  POST_COMMENTED = 'post_commented', // 帖子被评论
  POST_LIKED = 'post_liked', // 帖子被点赞
  SYSTEM = 'system', // 系统通知
}

@Entity('notifications')
export class Notification {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({
    type: 'enum',
    enum: NotificationType,
  })
  type: NotificationType;

  @Column('text')
  content: string;

  @Column({ default: false })
  isRead: boolean;

  @Column()
  userId: number;

  @Column({ nullable: true })
  relatedId: number; // 相关的图书ID或帖子ID

  @ManyToOne(() => User)
  @JoinColumn({ name: 'userId' })
  user: User;

  @CreateDateColumn()
  createdAt: Date;

  @UpdateDateColumn()
  updatedAt: Date;
}
